package bawei.com.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import bawei.com.bilibili.R;

/**
 * 作者：张宏达
 * 类的创建时间： 2017/3/10 13:30
 * 类的作用：发现界面上方展示recyclerview的适配器
 */

public class RcyAdapter_FindFragment_Show extends RecyclerView.Adapter<RcyAdapter_FindFragment_Show.ShowViewHolder> {

    Context mcontext;
    List<String> mlist;
    List<Integer> mheight;


    public RcyAdapter_FindFragment_Show(Context context, List<String> list) {
        mcontext = context;
        mlist = list;
        //随机高度集合
        mheight = new ArrayList<Integer>();
        for (int i = 0; i < mlist.size(); i++) {
            mheight.add((int) ( 50+Math.random() * 100));
        }
    }

    @Override
    public int getItemCount() {

        return mlist.size();
    }

    @Override
    public ShowViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ShowViewHolder holder = new ShowViewHolder(LayoutInflater.from(mcontext).inflate(R.layout.item_findfragment_recyclerview_show, parent, false));
        return holder;
    }


    @Override
    public void onBindViewHolder(ShowViewHolder holder, int position) {

        LayoutParams lp = holder.item_tv_show.getLayoutParams();
        lp.width = mheight.get(position);
        holder.item_tv_show.setLayoutParams(lp);
        holder.item_tv_show.setText(mlist.get(position));
    }


    class ShowViewHolder extends RecyclerView.ViewHolder {
        TextView item_tv_show;
        public ShowViewHolder(View itemView) {
            super(itemView);
            item_tv_show= (TextView) itemView.findViewById(R.id.item_tv_show);
        }
    }


}
